﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using App.Utilities.Web.Handlers;
using System.Data;
using CRMBiz;
using Newtonsoft.Json;
using CRMEntity;
using CRMWeb.Utilities.Context;

namespace CRMWeb.WebServices
{
    /// <summary>
    /// Summary description for ApplicationAssesment
    /// </summary>
    public class ApplicationAssesment : BaseHandler
    {

        public override void OnMethodInvoke(OnMethodInvokeArgs e)
        {
            context.Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);
            context.Response.Cache.SetExpires(DateTime.MinValue);
            context.Response.Cache.SetNoStore();
            //e.Cancel = true;
            SetResponseContentType(ResponseContentTypes.HTML);
        }

        public override void AfterMethodInvoke(object result)
        {
            base.AfterMethodInvoke(result);
        }


        #region Private Methods

        public void SelectAssesmentData(int app_id)
        {
            DataSet ds;
            string strJson = string.Empty;
            try
            {
                Assesment objAss = new Assesment();
                ds = objAss.GetAssesmentDataByAppID(app_id);
                if (ds.Tables[0].Rows.Count == 1)
                    context.Response.Write(JsonConvert.SerializeObject(ds.Tables[0]));
                else
                    context.Response.Write("0");
            }
            catch (Exception ex)
            {
                context.Response.Write("1");
                ErrorHandler.saveErrorLog(ex,CMSContext.CurrentUser.MemberName);
            }
        }

        public void saveAssesmentData(int AssesmentID, int app_id, string AccountNo, string Lender, string LastResult, string AssesmentDate, string Note, string hOperator)
        {
            try
            {
                int response;
                Assesment objass = new Assesment();
                objass.AssesmentID = AssesmentID;
                objass.app_id = app_id;
                objass.accountNo = AccountNo;
                objass.lender = Lender;
                objass.assesLastResult = LastResult;
                objass.assesLastDate = AssesmentDate;
                objass.note = Note;
                objass.hoperator = hOperator;

                response = objass.SaveAssesmentData();
                if (response > 0)
                    context.Response.Write(response);
                else
                    context.Response.Write("0");
            }
            catch (Exception ex)
            {
                context.Response.Write("1");
                ErrorHandler.saveErrorLog(ex,CMSContext.CurrentUser.MemberName);
            }
        }
        #endregion



    }
}